package com.kaifamiao.contraller;

import com.kaifamiao.model.AdminModel;
import com.kaifamiao.service.AdminService;
import com.kaifamiao.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AdminController {

    @Autowired
    private AdminService service;

    @RequestMapping(value = "/adminLogin")
    @CrossOrigin("*")
    public ResponseUtil login(@RequestParam(value = "adminName",required = false) String adminName,
                              @RequestParam(value = "password",required = false)String password){
        AdminModel model=new AdminModel();
        model.setAdminname(adminName);
        model.setPassword(password);
        System.out.println(model);
        List<AdminModel> list = service.findByAdmin(model);
        if(list.size() == 0){

            return ResponseUtil.error("请求失败");
        }else{
            model=service.findByAdminName(adminName);
            System.out.println(model);

            return ResponseUtil.ok("请求成功",model);
        }
    }
}
